<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>项目管理</title>
<link type="text/css"
	href="${pageContext.request.contextPath}/assets/plugins/jquery-easyui-1.4.2/themes/metro/easyui.css"
	rel="stylesheet" />
<link type="text/css"
	href="${pageContext.request.contextPath}/assets/plugins/jquery-easyui-1.4.2/themes/mobile.css"
	rel="stylesheet" />
<link type="text/css"
	href="${pageContext.request.contextPath}/assets/css/common.css"
	rel="stylesheet" />
<style type="text/css">
.main {
	margin-right: 15px;
}

ul {
	list-style: none;
}

.icon-list li a {
	cursor: pointer;
}
</style>
</head>
<body>
	<div class="main">
		<!--工具栏-->
		<div id="floatHead" class="toolbar-wrap">
			<div class="toolbar">
				<div class="box-wrap">
					<a class="menu-btn"></a>
					<div class="l-list">
						<ul class="icon-list">
							<li><a class="add" onclick="add()"><i></i><span>新增项目</span></a></li>
							<li><a class="all" onclick="selectAll()"><i></i><span>全选</span></a></li>
							<li><a class="del" onclick="delMore()"><i></i><span>批量删除</span></a></li>
						</ul>
						<div class="menu-list">
							<div class="rule-single-select single-select">
								<div class="boxwrap">
									<a class="select-tit" href="javascript:;"> <span>所有项目</span>
										<i></i>
									</a>
									<div class="select-items" style="z-index: 1;">
										<ul>
											<li id="-1" class="selected">所有项目</li>
											<li id="0">已录入</li>
											<li id="1">待审核</li>
											<li id="2">已审核</li>
											<li id="3">已发布</li>
											<li id="4">已招满</li>
											<li id="5">已停用</li>
										</ul>
									</div>
									<i class="arrow" style="z-index: 1; display: none;"></i>
								</div>
							</div>
						</div>
					</div>
					<div class="r-list">
						<input id="search" class="keyword" /> <a
							href="javascript:void(0);" class="btn-search"
							onclick="searchItem()">查询</a>
					</div>
				</div>
			</div>
		</div>
		<!--/工具栏-->

		<table id="tt"></table>
	</div>

	<script
		src="${pageContext.request.contextPath}/assets/js/jquery-1.11.2.min.js"
		charset="utf-8" type="text/javascript"></script>
	<script
		src="${pageContext.request.contextPath}/assets/plugins/jquery-easyui-1.4.2/jquery.easyui.min.js"
		charset="utf-8" type="text/javascript"></script>
	<script
		src="${pageContext.request.contextPath}/assets/plugins/jquery-easyui-1.4.2/locale/easyui-lang-zh_CN.js"
		charset="utf-8" type="text/javascript"></script>
	<script src="${pageContext.request.contextPath}/assets/js/common.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
	var contextPath = '<%=request.getContextPath()%>';
		$(function() {
			getTableList();
			$(window).resize(function() {
				//延迟执行,防止多次触发
				setTimeout(function() {
					$('#tt').datagrid('resize');
				}, 100);
			});
			//下拉框方法
			$('.select-tit i').click(function() {
				$('.boxwrap .select-items').css('display', 'block');
				$('.boxwrap .arrow').css('display', 'inline');
			})
			$(document).click(function(e) {
				var hasClass = $(e.target).parents().hasClass('boxwrap');
				if (!hasClass) {
					$('.boxwrap .select-items').css('display', 'none');
					$('.boxwrap .arrow').css('display', 'none');
				}
			})
			$('.select-items ul li').click(function() {
				$(this).parent().find('li').removeClass('selected');
				$(this).addClass('selected');
				$('.select-tit span').html($(this).html());
				$('.boxwrap .select-items').css('display', 'none');
				$('.boxwrap .arrow').css('display', 'none');
				getTableList();
			})
		})

		/*获取数据列表*/
		function getTableList() {
			var search = $('#search').val();
			var statusList = '0,1,2,3,4,5';
			var status_id = $('.select-items ul li.selected').attr('id');
			if (!$.isNullOrEmpty(status_id)) {
				if (status_id != '-1') {
					statusList = status_id;
				}
			}
			$('#tt').datagrid(
							{
								//height: $('body').height() - 270,
								nowrap : true,
								striped : true,
								collapsible : false,
								remoteSort : false,
								selectOnCheck : false,
								checkOnSelect : false,
								singleSelect : true,
								fitColumns : true,
								url : contextPath + "/bg/IM101.do?item_status="
										+ statusList + "&search="
										+ encodeURI(search) + "&rnd="
										+ Math.random(),
								columns : [ [
										{
											field : 'CK',
											title : '选择',
											align : 'center',
											width : 100,
											formatter : function(value, row,
													index) {
												if(row.STATUS == 0){
													return '<input name="check" data-code="'+row.CODE+'" type="checkbox"/>';
												}else{
													return '<input name="check" data-code="'+row.CODE+'" disabled="disabled" type="checkbox"/>';
												}
											}
										},
										{
											field : 'CODE',
											title : '项目编码',
											align : 'center',
											width : 100
										},
										{
											field : 'NAME',
											title : '项目名称',
											align : 'center',
											width : 100,
										},
										{
											field : 'PARENT_NAME',
											title : '项目类别',
											align : 'center',
											width : 100
										},
										{
											field : 'START_DATE',
											title : '开始日期',
											align : 'center',
											width : 100
										},
										{
											field : 'END_DATE',
											title : '结束日期',
											align : 'center',
											width : 100
										},
										{
											field : 'STATUS_NAME',
											title : '项目状态',
											align : 'center',
											width : 100
										},
										{
											field : 'OTHER1',
											title : '项目修改',
											align : 'center',
											width : 100,
											formatter : function(id, row, index) {
												if (row.STATUS == 0) {
													return '<button type="button" onclick="alter(\''
															+ row.CODE
															+ '\')" class="btn">修改</button>';
												} else {
													return '<button type="button" onclick="alter(\''
															+ row.CODE
															+ '\')" class="btn grey" disabled="disabled">修改</button>';
												}
											}
										},
										{
											field : 'OTHER2',
											title : '项目删除',
											align : 'center',
											width : 100,
											formatter : function(id, row, index) {
												if (row.STATUS == 0) {
													return '<button type="button" onclick="del(\''
															+ row.CODE
															+ '\')" class="btn">删除</button>';
												} else {
													return '<button type="button" onclick="del(\''
															+ row.CODE
															+ '\')" class="btn grey" disabled="disabled">删除</button>';
												}
											}
										},
										{
											field : 'OTHER3',
											title : '发送',
											align : 'center',
											width : 100,
											formatter : function(id, row, index) {
												if (row.STATUS == 0) {
													return '<button type="button" onclick="send(\''
															+ row.CODE
															+ '\')" class="btn">待审核</button>';
												} else {
													return '<button type="button" onclick="send(\''
															+ row.CODE
															+ '\')" class="btn grey" disabled="disabled">待审核</button>';
												}
											}
										} ] ],
								pagination : true,
								pageSize : 10,
								pageList : [ 10, 15, 30, 40 ],
								onDblClickRow :function(rowIndex,rowData){
									   show(rowData.CODE);
									  }
							});
		}
		//新增
		function add() {
			location.href = contextPath + "/bg/item_edit.do?action=add&rnd="
					+ Math.random();
		}
		//修改
		function alter(code) {
			location.href = contextPath + "/bg/item_edit.do?action=edit&code="
					+ code + "&rnd=" + Math.random();
		}
		//全选
		function selectAll() {
			//var unCheck = true;
/* 			$('input[name="check"]').each(function() {
				if (!$(this).prop('checked')) {
					$(this).prop("checked", true);
					unCheck = false;
				}
			}) */
			$('input[name="check"]').each(function(){
				if($(this).attr('disabled')!='disabled'){
					$(this).prop("checked", true);
				}
			})
			//if (unCheck) {
				//$('input[name="check"]').prop("checked", false);
			//}
		}
		//批量删除
		function delMore() {
			var codeList = '';
			if ($('input[name="check"]:checked').size() < 1) {
				$.messager.show({title:'提示',msg:'请选择需要删除的项目！',showType:'slide'});
				return;
			}
			$('input[name="check"]:checked').each(function() {
				codeList += $(this).attr("data-code") + ",";
			})
			codeList = codeList.substring(0, codeList.length - 1);
			del(codeList);
		}
		//删除
		function del(codeList) {
			$.ajax({
				url : contextPath + "/bg/IM105.do",
				data : {
					"codeList" : codeList,
					"rnd" : Math.random()
				},
				dataType : 'json',
				success : function(data, textStatus, jqXHR) {
					if (data.status == 'true') {
						$.messager.show({title:'提示',msg:'删除成功！',showType:'slide'});
						getTableList();
					} else {
						$.messager.show({title:'提示',msg:'删除失败！',showType:'slide'});
					}
				}
			})
		}
		//查询
		function searchItem() {
			getTableList();
		}
		//发送
		function send(code) {
			$.ajax({
				url : contextPath + "/bg/IM106.do",
				data : {
					"code" : code,
					"item_status" : "1",
					"rnd" : Math.random()
				},
				dataType : 'json',
				success : function(data, textStatus, jqXHR) {
					if (data.status == 'true') {
						$.messager.show({title:'提示',msg:'发送成功！',showType:'slide'});
						getTableList();
					} else {
						$.messager.show({title:'提示',msg:'发送失败！',showType:'slide'});
					}
				}
			})
		}
		//查看
		function show(code){
			location.href = contextPath + "/bg/item_edit.do?action=edit&show=1&code="
			+ code + "&rnd=" + Math.random();
		}
	</script>
</body>
</html>